<?php
/**
 * author      :chenwenwen
 * createTime  :2020-05-02 14:57
 * description :
 */

namespace app\api\controller;

use app\BaseController;

class Login extends BaseController {
    public function index(): object {
        $phone_number = $this->request->param('phone_number','');
        $code = input('param.code',0,'intval');
        $type = input('param.type',0,'intval');

        //参数校验
        $data = [
            'phone_number'=>$phone_number,
            'code'=>$code,
            'type'=>$type
        ];
        $validate = new \app\api\validate\User();
        if(!$validate->scene('login')->check($data)) {
            return show(config('status.error'),$validate->getError());
        }

        $result = (new \app\common\business\User())->login($data);

        if($result) return show(config('status.success'),'登录成功',$result);

        return show(config('status.error'),'登录失败');

    }
}